home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / human interface toolbox / password / sample.h < prev   
Encoding:
Text File  |  2000-06-23  |  8.4 KB  |  193 lines

  1. /*
  2.     File:        Sample.h
  3.  
  4.     Contains:    MultiFinder-Aware Simple Sample Application
  5.                 Sample is an example application that demonstrates how to
  6.                 initialize the commonly used toolbox managers, operate 
  7.                 successfully under MultiFinder, handle desk accessories, 
  8.                 and create, grow, and zoom windows.
  9.     
  10.                 It does not by any means demonstrate all the techniques 
  11.                 you need for a large application. In particular, Sample 
  12.                 does not cover exception handling, multiple windows/documents, 
  13.                 sophisticated memory management, printing, or undo. All of 
  14.                 these are vital parts of a normal full-sized application.
  15.     
  16.                 This application is an example of the form of a Macintosh 
  17.                 application; it is NOT a template. It is NOT intended to be 
  18.                 used as a foundation for the next world-class, best-selling, 
  19.                 600K application. A stick figure drawing of the human body may 
  20.                 be a good example of the form for a painting, but that does not 
  21.                 mean it should be used as the basis for the next Mona Lisa.
  22.             
  23.                 We recommend that you review this program or TESample before 
  24.                 beginning a new application.
  25.  
  26.     Written by:     
  27.  
  28.     Copyright:    Copyright © 1988-1999 by Apple Computer, Inc., All Rights Reserved.
  29.  
  30.                 You may incorporate this Apple sample source code into your program(s) without
  31.                 restriction. This Apple sample source code has been provided "AS IS" and the
  32.                 responsibility for its operation is yours. You are not permitted to redistribute
  33.                 this Apple sample source code as "Apple sample source code" after having made
  34.                 changes. If you're going to re-distribute the source, we require that you make
  35.                 it clear in the source that the code was descended from Apple sample source
  36.                 code, but that you've made changes.
  37.  
  38.     Change History (most recent first):
  39.                 8/9/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  40.                 
  41.  
  42. */
  43.  
  44. /*    These #defines correspond to values defined in the Pascal source code.
  45.     Sample.c and Sample.r include this file. */
  46.  
  47. /*    Determining an application's minimum size to request from MultiFinder depends
  48.     on many things, each of which can be unique to an application's function,
  49.     the anticipated environment, the developer's attitude of what constitutes
  50.     reasonable functionality and performance, etc. Here is a list of some things to
  51.     consider when determining the minimum size (and preferred size) for your
  52.     application. The list is pretty much in order of importance, but by no means
  53.     complete.
  54.     
  55.     1.    What is the minimum size needed to give almost 100 percent assurance
  56.         that the application won't crash because it ran out of memory? This
  57.         includes not only things that you do have direct control over such as
  58.         checking for NIL handles and pointers, but also things that some
  59.         feel are not so much under their control such as QuickDraw and the
  60.         Segment Loader.
  61.         
  62.     2.    What kind of performance can a user expect from the application when
  63.         it is running in the minimum memory configuration? Performance includes
  64.         not only speed in handling data, but also things like how many documents
  65.         can be opened, etc.
  66.         
  67.     3.    What are the typical sizes of scraps [is a boy dog] that a user might
  68.         wish to work with when lauching or switching to your application? If
  69.         the amount of memory is too small, the scrap may get lost [will have
  70.         to be shot]. This can be quite frustrating to the user.
  71.         
  72.     4.    The previous items have concentrated on topics that tend to cause an
  73.         increase in the minimum size to request from MultiFinder. On the flip
  74.         side, however, should be the consideration of what environments the
  75.         application may be running in. There may be a high probability that
  76.         many users with relatively small memory configurations will want to
  77.         avail themselves of your application. Or, many users might want to use it
  78.         while several other, possibly related/complementary applications are
  79.         running. If that is the case, it would be helpful to have a fairly
  80.         small minimum size.
  81.     
  82.     So, what did we decide on Sample? First, Sample has little risk of
  83.     running out of memory once it starts. Second, performance isn't much
  84.     of an issue since it doesn't do much and multiple windows are not
  85.     allowed. Third, there are no edit operations in Sample itself, so we
  86.     just want to provide enough space for a reasonable scrap to survive
  87.     between desk accessory launches. Lastly, Sample should intrude as little
  88.     as possible, so the effort should be towards making it as small as possible.
  89.     We looked at some heap dumps while the application was running under
  90.     various partition sizes. With a size of 23K, there was approximately
  91.     8-9K free, which is a good 'slop' factor in an application like this
  92.     which doesn't do much, but where we'd still like the scrap to survive
  93.     most of the time. */
  94.  
  95. #define kMinSize    23                /* application's minimum size (in K) */
  96.  
  97. /*    We made the preferred size bigger than the minimum size by 12K, so that
  98.     there would be even more room for the scrap, FKEYs, etc. */
  99.  
  100. #define kPrefSize    35                /* application's preferred size (in K) */
  101.  
  102. #define    rMenuBar    128                /* application's menu bar */
  103. #define    rAboutAlert    128                /* about alert */
  104. #define    rUserAlert    129                /* error user alert */
  105. #define    rWindow        128                /* application's window */
  106.  
  107. /* kSysEnvironsVersion is passed to SysEnvirons to tell it which version of the
  108.    SysEnvRec we understand. */
  109.  
  110. #define    kSysEnvironsVersion        1
  111.  
  112. /* kOSEvent is the event number of the suspend/resume and mouse-moved events sent
  113.    by MultiFinder. Once we determine that an event is an osEvent, we look at the
  114.    high byte of the message sent to determine which kind it is. To differentiate
  115.    suspend and resume events we check the resumeMask bit. */
  116.  
  117. #define    kOSEvent                15    /* event used by MultiFinder */
  118. #define    kSuspendResumeMessage    1        /* high byte of suspend/resume event message */
  119. #define    kResumeMask                1        /* bit of message field for resume vs. suspend */
  120. #define    kMouseMovedMessage        0xFA    /* high byte of mouse-moved event message */
  121. #define    kNoEvents                0        /* no events mask */
  122.  
  123. /* The following constants are used to identify menus and their items. The menu IDs
  124.    have an "m" prefix and the item numbers within each menu have an "i" prefix. */
  125.  
  126. #define    mApple                    128        /* Apple menu */
  127. #define    iAbout                    1
  128.  
  129. #define    mFile                    129        /* File menu */
  130. #define    iNew                    1
  131. #define    iClose                    4
  132. #define    iQuit                    12
  133.  
  134. #define    mEdit                    130        /* Edit menu */
  135. #define    iUndo                    1
  136. #define    iCut                    3
  137. #define    iCopy                    4
  138. #define    iPaste                    5
  139. #define    iClear                    6
  140.  
  141. #define    mPassword                131        /* Password menu */
  142. #define    iTwoItem                1
  143. #define    iDifferentFont            2
  144. #define    iInternalBuffer            3
  145.  
  146. /*    1.01 - kTopLeft - This is for positioning the Disk Initialization dialogs. */
  147.  
  148. #define kDITop                    0x0050
  149. #define kDILeft                    0x0070
  150.  
  151. /*    1.01 - kMinHeap - This is the minimum result from the following
  152.     equation:
  153.         
  154.         ORD(GetApplLimit) - ORD(ApplicZone)
  155.         
  156.     for the application to run. It will insure that enough memory will
  157.     be around for reasonable-sized scraps, FKEYs, etc. to exist with the
  158.     application, and still give the application some 'breathing room'.
  159.     To derive this number, we ran under a MultiFinder partition that was
  160.     our requested minimum size, as given in the 'SIZE' resource. */
  161.      
  162. #define kMinHeap                21 * 1024
  163.     
  164. /*    1.01 - kMinSpace - This is the minimum result from PurgeSpace, when called
  165.     at initialization time, for the application to run. This number acts
  166.     as a double-check to insure that there really is enough memory for the
  167.     application to run, including what has been taken up already by
  168.     pre-loaded resources, the scrap, code, and other sundry memory blocks. */
  169.      
  170. #define kMinSpace                8 * 1024
  171.  
  172. /* kExtremeNeg and kExtremePos are used to set up wide open rectangles and regions. */
  173.  
  174. #define kExtremeNeg                -32768
  175. #define kExtremePos                32767 - 1 /* required to address an old region bug */
  176.  
  177. /* these #defines are used to set enable/disable flags of a menu */
  178.  
  179. #define AllItems    0b1111111111111111111111111111111    /* 31 flags */
  180. #define NoItems        0b0000000000000000000000000000000
  181. #define MenuItem1    0b0000000000000000000000000000001
  182. #define MenuItem2    0b0000000000000000000000000000010
  183. #define MenuItem3    0b0000000000000000000000000000100
  184. #define MenuItem4    0b0000000000000000000000000001000
  185. #define MenuItem5    0b0000000000000000000000000010000
  186. #define MenuItem6    0b0000000000000000000000000100000
  187. #define MenuItem7    0b0000000000000000000000001000000
  188. #define MenuItem8    0b0000000000000000000000010000000
  189. #define MenuItem9    0b0000000000000000000000100000000
  190. #define MenuItem10    0b0000000000000000000001000000000
  191. #define MenuItem11    0b0000000000000000000010000000000
  192. #define MenuItem12    0b0000000000000000000100000000000
  193.